﻿namespace Specifications.Extensions
{
    using System;
    using System.ComponentModel;
    using System.Linq.Expressions;
    using System.Reflection;

    public static class AssertExtensions
    {
        public static SinglePropertyAssertion<T, K> AssertThatProperty<T, K>(this T propertyOwner,
                                                                             Expression<Func<K>> property)
            where T : class, INotifyPropertyChanged
        {
            return new SinglePropertyAssertion<T, K>(propertyOwner, property);
        }

        public static AllPropertiesAssertion<T> AssertThatAllProperties<T>(this T propertyOwner)
            where T : class, INotifyPropertyChanged
        {
            return new AllPropertiesAssertion<T>(propertyOwner);
        }

        public static PropertyInfo GetPropertyInfo<K>(this Expression<Func<K>> property)
        {
            var memberExpression = (MemberExpression) property.Body;
            return (PropertyInfo) memberExpression.Member;
        }
    }
}